// 实现IPerson类型
// 数据 :

// 可选项 : 可写可不写 ?
type IPerson = {
  name: string;
  age: number;
  occupation?: string;
  role?: string;
};

let persons: IPerson[] = [
  {
    name: "Max Mustermann",
    age: 25,
    occupation: "Chimney sweep",
  },
  {
    name: "Jane Doe",
    age: 32,
    role: "Administrator",
  },
  {
    name: "Kate Müller",
    age: 23,
    occupation: "Astronaut",
  },
  {
    name: "Bruce Willis",
    age: 64,
    role: "World saver",
  },
];

function logPerson(user: IPerson): { userId: number } {
  console.log(` - ${user.name}, ${user.role} ,  ${user.occupation}`);
  return { userId: 12 }; // 在此补充代码
}
// 保证此步骤不错
// arr.map((item)=>{return 1})  // [1,1,1,1]
let arr = persons.map(logPerson);
arr[0].userId = 10; //  不报错

type Common = {
  name: string;
  avator: string;
  time: string;
}
type Asker = {
  questions: {
    title: string;
    picture: string[];
  };
};
type Answer = {
  answers: {
    text: string;
    audio: {
      url: string;
      total: number;
    };
  };
};

// & : 交叉类型  合并两个类型  写法 : 类型A & 类型B  ==> 类型A+ 类型B
type AskConfigList = [{ asker: Asker & Common; answer: Answer & Common }];

const arrList: AskConfigList = [
  {
    asker: {
      name: "张三",
      avator: "https://img.yzcdn.cn/vant/cat.jpeg",
      time: "2020-06-24",
      questions: {
        title: "你是谁",
        picture: [
          "https://img.yzcdn.cn/vant/cat.jpeg",
          "https://img.yzcdn.cn/vant/cat.jpeg",
          "https://img.yzcdn.cn/vant/cat.jpeg",
        ],
      },
    },
    answer: {
      name: "李四",
      avator: "https://img.yzcdn.cn/vant/cat.jpeg",
      time: "2020-06-24",
      answers: {
        text: "我是李四",
        audio: {
          url: "https://img.yzcdn.cn/vant/cat.jpeg",
          total: 10,
        },
      },
    },
  },
];
